﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace CLEX.Service.DataContracts
{
    [DataContract]
    public struct AggregateData : IEquatable<AggregateData>
    {
        [DataMember]
        private readonly AggregateTypeData aggregateType;
        [DataMember]
        private readonly string column;

        public AggregateTypeData AggregateType
        {
            get { return aggregateType; }
        }

        public string Column
        {
            get { return column; }
        }

        public AggregateData(AggregateTypeData aggregateType, string column)
        {
            this.aggregateType = aggregateType;
            this.column = column;
        }

        public override bool Equals(object obj)
        {
            if (obj is AggregateData)
            {
                return Equals((AggregateData)obj);
            }
            else
            {
                return false;
            }
        }

        public override int GetHashCode()
        {
            return aggregateType.GetHashCode() ^ (column == null ? 0 : column.GetHashCode());
        }

        public bool Equals(AggregateData other)
        {
            return this.aggregateType == other.aggregateType && this.column == other.column;
        }

        public static bool operator ==(AggregateData left, AggregateData right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(AggregateData left, AggregateData right)
        {
            return !(left == right);
        }
    }
}
